﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SACM.Common.Objects;

namespace SACM
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        public string TituloSistema
        {
            get { return LblTituloSistema.Text; }
            set { LblTituloSistema.Text = value; }
        }

        public string TituloPagina
        {
            get { return LblTitulo.Text; }
            set { LblTitulo.Text = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "IsPostBack", "var isPostBack = false;", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "IsPostBack", "var isPostBack = true;", true);
            }
            
            hdnIdEmpresa.Value = ((Empresa)Session["Empresa"]).IdEmpresa.ToString();
        }

        public void alert(string msg)
        {
            if (Page.IsPostBack)
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\");", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\");", true);
                //Response.Write("<script type='text/javascript'>ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\"); </script>");
            }
        }

        public void alert(string msg, string codigoExtra)
        {
            if (Page.IsPostBack)
            {
                ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\");" + codigoExtra, true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\");" + codigoExtra, true);
            }
        }

        public void alert(string msg, string codigoExtra, bool ejecutaEnBotonAceptar)
        {
            if (ejecutaEnBotonAceptar)
            {
                if (Page.IsPostBack)
                {
                    ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\",function () { " + codigoExtra + "});", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "ShowMsg(\"" + msg.Replace("'", "\\'").Replace("\"", "\\" + "\"") + "\",function () { " + codigoExtra + "});", true);
                }
            }
            else
            {
                alert(msg, codigoExtra);
            }
        }

        public void alertExito()
        {
            alert("Operación exitosa");
        }

        public void alertExito(string codigoExtra, bool ejecutaEnBotonAceptar = false)
        {
            alert("Operación exitosa", codigoExtra, ejecutaEnBotonAceptar);
        }

        public void alertSinDatos()
        {
            alert("No se encontraron resultados");
        }

        public void alertSinDatos(string codigoExtra)
        {
            alert("No se encontraron resultados", codigoExtra);
        }
    }
}
